package com.magoldeditor.model.entity;

import java.util.HashMap;

import com.magoldeditor.model.PainterState;

public class MaEditorEntityFactory implements IEntityFactory {
	
	public static final String ENTITY_BATTERY = "Battery", ENTITY_BULB = "Bulb", ENTITY_CLOUD = "Cloud", 
			ENTITY_EJECTOR = "Ejector", ENTITY_PIPEENTRANCE = "PipeEntrance", ENTITY_FAN = "Fan";
	
	private PainterState state = PainterState.ENTITY_STATE;
	

	private HashMap<String, IEntity> spriteTable = new HashMap<String, IEntity>();
	public MaEditorEntityFactory() {
		//spriteTable.put(ENTITY_ACCELERATOR, new Accelerator(ENTITY_ACCELERATOR));
		spriteTable.put(ENTITY_BATTERY, new Battery(ENTITY_BATTERY));
		spriteTable.put(ENTITY_BULB, new Bulb(ENTITY_BULB));
		spriteTable.put(ENTITY_CLOUD, new Cloud(ENTITY_CLOUD));
		spriteTable.put(ENTITY_EJECTOR, new Ejector(ENTITY_EJECTOR));
		spriteTable.put(ENTITY_PIPEENTRANCE, new PipeEntrance(ENTITY_PIPEENTRANCE));
		spriteTable.put(ENTITY_FAN, new Fan(ENTITY_FAN));
	}
	
	@Override
	public IEntity createEntity(String name) {
		IEntity entity = null;
		
		switch(state) {
		case ENTITY_STATE:
			entity = spriteTable.get(name);
		}
		
		if (entity != null) return (IEntity) entity.clone();
		else return null;
	}
	
	@Override
	public void setState(PainterState index) {
		this.state = index;
	}

	@Override
	public PainterState getState() {
		return this.state;
	}
	

}
